//
//  SKUDetailTakeinVC.m
//  ZITHER
//
//  Created by weixin on 2018/8/17.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailTakeinVC.h"
#import "SKUDetailTakeinTbV.h"
#import "AcceptPriceListModel.h"


@interface SKUDetailTakeinVC ()
@property (nonatomic,strong)SKUDetailTakeinTbV * tb;
@property (nonatomic,assign)NSInteger page;
@end

@implementation SKUDetailTakeinVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
//    [self setLoad];
    [self setUI];
}

-(void)setIndex:(NSInteger)index{
    _index = index;
    if (index == 3) {
        self.tb.type = YES;
    }
}


-(void)setLoad{
    
        if (self.index == 2) {
        [[serviceDefualt loadNoInterestPrice:self.goodsId  reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
            if (x.success) {
                
                NSArray *arr = x.responseRawData[@"data"];
                
                
                if ((arr != nil && ![arr isKindOfClass:[NSNull class]]) || arr.count == 0){
                    [Tools showTips:@"暂无更多数据"];
                    return ;
                }
                
                if(!x.responseRawData[@"data"]){
                    [Tools showTips:@"暂无更多数据"];
                    return ;
                }
                
                id obj = x.responseRawData[@"data"];
                BOOL isNull = [obj isEqual:[NSNull null]];

                if (isNull) {
                    [Tools showTips:@"暂无更多数据"];
                    return ;
                }
                
                NSMutableArray *arrM = [[NSMutableArray alloc]init];
                for (NSDictionary *dic in arr) {
                    AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
                    [arrM addObject:model];
                }
                
                self.tb.arrM = arrM;
                
            }else{
                
            }
        }];
        }else if (self.index == 3){
            [[serviceDefualt loadgetHistoryEnquiryList:self.goodsId page:0 reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
                if (x.success) {
                    
                    NSArray *arr = x.responseRawData[@"data"];
                    if (arr.count == 0) {
                        [Tools showTips:@"没有数据"];
                        return ;
                    }
                    NSMutableArray *arrM = [[NSMutableArray alloc]init];
                    for (NSDictionary *dic in arr) {
                        AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
                        [arrM addObject:model];
                    }
                    self.tb.arrM = arrM;}else{
                         [Tools showTips:x.errorInfo];
                    }
            }];
        }else if (self.index == 4){
                    [[serviceDefualt loadGetAcceptPriceList:self.goodsId page:self.page reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
                        if (x.success) {
                            
 
                            NSArray *arr = x.responseRawData[@"data"];
                            
                            if (arr.count == 0) {
                                if (self.page == 0) {
                                    [Tools showTips:@"暂无更多数据"];
                                    [self.tb.mj_header endRefreshing];
                                    [self.tb.mj_footer endRefreshing];
                                }else{
                                    [self.tb.mj_footer endRefreshingWithNoMoreData];
                                }
                                return ;
                            }
                            NSMutableArray *arrM = [[NSMutableArray alloc]init];
                            for (NSDictionary *dic in arr) {
                                AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
                                [arrM addObject:model];
                            }
            
                            self.tb.arrM = arrM;
            
                        }else{
            
                        }
            
                    }];
        }else{
            [[serviceDefualt loadgetHistoryEnquiryList:self.goodsId page:0 reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
                if (x.success) {
                    
                    
                    NSArray *arr = x.responseRawData[@"data"];

                    [self.tb setNoMoreDataBg:YES NoDataState:NoMoreDataStateDefault];
                 
                    
                    if (arr.count == 0) {
                        if (self.page == 0) {
                            [self.tb setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
                            self.tb.noMoreDateView.title.text = @"暂无历史记录";
                            [Tools showTips:@"暂无更多数据"];
                            [self.tb endRefreshing];
                            [self.tb endRefreshing];
                            [self.tb reloadData];
                            [self.tb.mj_footer endRefreshingWithNoMoreData];
                        }else{
                            [self.tb.mj_footer endRefreshingWithNoMoreData];
                        }
                        return ;
                    }
                    NSMutableArray *arrM = [[NSMutableArray alloc]init];
                    for (NSDictionary *dic in arr) {
                        AcceptPriceListModel *model = [AcceptPriceListModel yy_modelWithJSON:dic];
                        [arrM addObject:model];
                    }
                    self.tb.arrM = arrM;}else{
                         [Tools showTips:x.errorInfo];
                    }
            }];
    }
    
    
}

-(void)setNav{
    [self.baseNavigationView setHiddenNav:NO VC:self];
    [self.baseNavigationView NavigationBarStyle:1];
    self.baseNavigationView.navViewStyle.title.text = self.leb.text;

//    self.tabBarController.tabBar.hidden = YES;
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//    self.navigationController.navigationBar.shadowImage = [UIImage new];
//    [self.baseNavigationView setBackgroundColor:[UIColor clearColor]];
//    self.baseNavigationView.bottomLineView.backgroundColor = [UIColor clearColor];
//    self.baseNavigationView.leftButton1.hidden = YES;
//
//    /* TODO: ================= 导航栏箭头颜色 =================*/
//    QMUIButton *btn = [[QMUIButton alloc]initWithFrame:CGRectMake(14,kStatusBarHeight+5,40,40)];
//    [btn setImage:[UIImage imageNamed:@"common_back"] forState:UIControlStateNormal];
//    [self.view addSubview:btn];
//    @weakify(self);
//    [[btn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
//        @strongify(self);
//        [self.navigationController popViewControllerAnimated:YES];
//    }];
    
}



-(void)setUI{

//    [self.view addSubview:self.leb];
    
    [self.view addSubview:self.tb];
    
    
}


-(void)setGoodsId:(NSString *)goodsId{
    _goodsId = goodsId;
    [self setLoad];
}


-(SKUDetailTakeinTbV *)tb{
    if (!_tb) {
        _tb = [[SKUDetailTakeinTbV alloc]initWithFrame:CGRectMake(0, NaviHeight, kScreenW, kScreenH-NaviHeight)];
//        _tb.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 20)];
    }
    return _tb;
}

-(QMUILabel *)leb{
    if (!_leb) {
        _leb = [[QMUILabel alloc]initWithFrame:CGRectMake(20,kStatusBarHeight+50, 200, 22)];
        _leb.text = @"接受的报价";
        _leb.font = [UIFont systemFontOfSize:22];
        _leb.textColor = [UIColor blackColor];
    }
    return _leb;
}



@end
